package com.example.AIstudy.security;


import com.example.AIstudy.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

//@Service
//public class DbUserDetailService implements UserDetailsService {
//
//    @Autowired
//    UserServiceImpl userService;
//
////    @Value("${teacher.Authority}")
////    public String teacherAuthortiStr;
////    @Value("${student.Authority}")
////    public String studentAuthortiStr;
//
//
//    //构建的userdetail中的password为openID
//    @Override
//    public UserDetails loadUserByUsername(String openID) throws UsernameNotFoundException {
//        com.example.AIstudy.domain.User user = userService.getUserByOpenID(openID);
//        if (user == null) {
//            return null;
//        }
//        return User.builder()
//                .username(user.getNickname())
//                .password(openID)
//                .authorities(getAuthorities(user))
//                .build();
//    }
//
//    public GrantedAuthority[] getAuthorities(com.example.AIstudy.domain.User user) {
//        //查看用户有哪些权限
//        List<GrantedAuthority> authorities = new ArrayList<>();
//
//        //只可以删除/修改自己的信息，增加这个作为权限判断
//        authorities.add(new SimpleGrantedAuthority(user.getId().toString()));
//        authorities.add(new SimpleGrantedAuthority(user.getNickname()));
//        //把用户的身份信息也放在token中
//        return authorities.toArray(new GrantedAuthority[authorities.size()]);
//    }
//
//}
